package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.PmsAlbum;
import com.ruoyi.mall.service.IPmsAlbumService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品相册Controller
 *
 * @author zhanghang
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/mall/album")
public class PmsAlbumController extends BaseController {
    @Autowired
    private IPmsAlbumService pmsAlbumService;

    /**
     * 查询商品相册列表
     */
    @PreAuthorize("@ss.hasPermi('mall:album:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsAlbum pmsAlbum) {
        startPage();
        List<PmsAlbum> list = pmsAlbumService.selectPmsAlbumList(pmsAlbum);
        return getDataTable(list);
    }

    /**
     * 导出商品相册列表
     */
    @PreAuthorize("@ss.hasPermi('mall:album:export')")
    @Log(title = "商品相册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsAlbum pmsAlbum) {
        List<PmsAlbum> list = pmsAlbumService.selectPmsAlbumList(pmsAlbum);
        ExcelUtil<PmsAlbum> util = new ExcelUtil<PmsAlbum>(PmsAlbum.class);
        util.exportExcel(response, list, "商品相册数据");
    }

    /**
     * 获取商品相册详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:album:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pmsAlbumService.selectPmsAlbumById(id));
    }

    /**
     * 新增商品相册
     */
    @PreAuthorize("@ss.hasPermi('mall:album:add')")
    @Log(title = "商品相册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsAlbum pmsAlbum) {
        return toAjax(pmsAlbumService.insertPmsAlbum(pmsAlbum));
    }

    /**
     * 修改商品相册
     */
    @PreAuthorize("@ss.hasPermi('mall:album:edit')")
    @Log(title = "商品相册", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsAlbum pmsAlbum) {
        return toAjax(pmsAlbumService.updatePmsAlbum(pmsAlbum));
    }

    /**
     * 删除商品相册
     */
    @PreAuthorize("@ss.hasPermi('mall:album:remove')")
    @Log(title = "商品相册", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pmsAlbumService.deletePmsAlbumByIds(ids));
    }
}
